package cn.tlb.gl.game.rebuild2;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

/**
 * Created by 汤林冰 on 2016/1/13 16:33.
 */
public class BufferUtil {
    public static FloatBuffer wrap(float fs[]){
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fs.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
        floatBuffer.put(fs);
        floatBuffer.position(0);
        return floatBuffer;
    }

    public static IntBuffer wrap(int ints[]){
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(ints.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        IntBuffer intBuffer = byteBuffer.asIntBuffer();
        intBuffer.put(ints);
        intBuffer.position(0);
        return intBuffer;
    }

    public static ByteBuffer wrap(byte bytes[]){
        return ByteBuffer.wrap(bytes);
    }
}
